﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
   public class ChiTietVatTuDAO
    {
       public List<ChiTietVatTuDTO> DanhSachChiTietVatTu()
       {
           List<ChiTietVatTuDTO> kq = new List<ChiTietVatTuDTO>();
           DataProvider dp = new DataProvider();
           dp.Connect();
           string strsql = "select*from ChiTietVatTu";
           SqlDataReader dr = dp.ExecuteQuery(strsql);
           if (dr.HasRows)
           {
               while (dr.Read())
               {
                   ChiTietVatTuDTO ct = new ChiTietVatTuDTO();
                   ct.VT_ID = int.Parse(dr["VT_ID"].ToString());
                   ct.SoLuong=int.Parse(dr["SoLuong"].ToString());
                   ct.MaLoaiPhong=int.Parse(dr["MaLoaiPhong"].ToString());
                   kq.Add(ct);
               }
           }

           return kq;
       }
       public Boolean ThemChiTietVatTu(ChiTietVatTuDTO ct)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql="insert into ChiTietVatTu(VT_ID,MaLoaiPhong,SoLuong)";
           strsql += " values(" + ct.VT_ID + "," + ct.MaLoaiPhong + "," + ct.SoLuong + ")";
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;

       }
       public Boolean XoaChiTietVatTu(ChiTietVatTuDTO ct)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql = "delete from ChiTietVatTu where VT_ID="+ct.VT_ID+" and MaLoaiPhong="+ct.MaLoaiPhong;
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;

       }
       public Boolean CapNhatChiTietVatTu(ChiTietVatTuDTO ct)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           string strsql = "update ChiTietVatTu set SoLuong="+ct.SoLuong+" where VT_ID="+ct.VT_ID+" and MaLoaiPhong="+ct.MaLoaiPhong;
           dp.Connect();
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;

       }
    }
}
